package com.nsoft.thickclient.trackMove.vehicle;

import java.awt.Dimension;
import java.util.ArrayList;
import java.util.List;

import com.nsoft.server.serviceImpl.FacadeFactoryImpl;
import com.nsoft.thickclient.controller.ApplicationController;
import com.nsoft.thickclient.trackMove.intr.vehicle.Vehicle;
import com.nsoft.thickclient.trackMove.search.SearchAction;
import com.nsoft.thickclient.trackMove.search.SearchView;
import com.nsoft.thickclient.trackMove.search.SearchViewController;

public class SearchVehicleAction implements SearchAction<Vehicle> {

	public void delete(Vehicle bean) {
		// TODO Auto-generated method stub

	}

	public void edit(Vehicle bean, ApplicationController applicationController) {
		VehicleViewController controller = new VehicleViewController(true);
		applicationController.openScreen(controller, new Dimension(750, 500));
		controller.getVehicleView().setWorkingBean(bean);
	}

	public Vehicle getNewBean() {
		return new Vehicle();
	}

	public SearchView<Vehicle> getView(SearchViewController<Vehicle> controller) {
		List<Vehicle> list = new ArrayList<Vehicle>();
		for (int i = 0; i < 10; i++) {
			Vehicle vehicle = new Vehicle();
			vehicle.setRegistrationNo("KS 51 Q607" + i);
			vehicle.setOwner("owner -> " + i);
			vehicle.setTonnage(100l + i * 10);
			list.add(vehicle);
		}

		VehicleView vehicleView = new VehicleView(new Vehicle(), false);
		String[] properties = { "registrationNo", "owner", "tonnage" };
		String[] headers = { "Registration No", "Owner", "Capacity(Tons)" };
		SearchView<Vehicle> searchView = new SearchView<Vehicle>(list,
				properties, headers, vehicleView, controller);
		return searchView;
	}

	public List<Vehicle> search(Vehicle bean) {
		return FacadeFactoryImpl.getVechileService().searchVechiles(bean);

	}

}
